let ajax = require("./ajax.js");

/**
 * 用户是否登录
 */
function isLogin() {
  let token = wx.getStorageSync('token'),
    member = wx.getStorageSync('member');
  if (token && typeof member != 'Object') {
    return true;
  }
  console.log(token, member);
  wx.redirectTo({
    url: '/pages/password_login/password_login',
  })
}

/**
 * 确认登录服务器
 */
function realLogin(callback) {
  ajax.requestPost(ajax.ajaxUrl() + 'member/is-login', {}, 'post', '', function(res) {
    callback(res);
  }, function(res) {
    wx.showToast({
      title: '网络异常',
      icon: 'none'
    });
  });
}

module.exports = {
  isLogin: isLogin,
  realLogin: realLogin,
}